package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    /**
     * 员工分页查询
     *
     * @param start
     * @param pagesize
     * @return ArrayList<Employee>
     */
    ArrayList<Employee> searchEmployee(String name, int start, int pagesize);


    /**
     * 新增员工
     *
     * @param employee
     * @return
     */
    @AutoFill(value = OperationType.INSERT)
    void addEmp(Employee employee);


    /**
     * 员工分页查询count
     *
     * @return Result<PageResult>
     */
    @Select("Select count(*) from employee")
    Long getCount();


    /**
     * 员工帐号状态修改
     *
     * @return
     */
    @Update("update employee set status = #{status} where id=#{id}")
    void changeStatus(int status, int id);


    /**
     * 修改密码
     *
     * @param passwordEditDTO
     * @return
     */
    @Update("update employee set password=#{newPassword} where id=#{empId}")
    void changePassword(PasswordEditDTO passwordEditDTO);

    @Select("select password from employee where id =#{empId}")
    String searchPassword(Long empId);


    /**
     * 修改员工信息
     *
     * @return
     */
    @Update("update employee set id_number=#{idNumber},name=#{name},phone=#{phone},sex=#{sex},username=#{username},update_time=#{updateTime},update_user=#{updateUser} where id=#{id} ")
    @AutoFill(value = OperationType.UPDATE)
    void changeEmp(Employee employee);


    /**
     * 根据ID查询员工回显
     *
     * @param id
     * @return
     */
    @Select("SELECT *from employee where id =#{id}")
    Employee searchId(int id);
}
